<template>
  <el-dialog
    title="选择商品"
    :visible.sync="visible"
    width="845px"
    :before-close="handleClose"
    class="material"
    style="user-select: none;"
  >
    <div class="clearfix">
      <div
        class="img_box"
        style="background:#fff;margin:10px 22px;padding-bottom:5px;height:290px;"
      >
        <div
          v-for="(item, index) in listData"
          :key="index"
          class="img_item_border"
          :style="{ borderColor: item.check ? '#3587fc' : '' }"
          @click="checkHandle(index)"
        >
          <img
            :src="
              $store.state.qiniu +
                item.src.split(',')[0] +
                $store.state.imgRotate
            "
          />
          <div style="height:63px;position:relative;">
            <div style=" width: 66px; height: 42px; overflow: hidden;">
              {{ item.goods_name }}
            </div>
            <div style="position:absolute;bottom:0px;">
              <span>￥{{ item.join_low_price }}</span>
            </div>
          </div>
        </div>
        <div
          v-if="listData.length <= 0"
          style="text-align:center;margin:150px 0;"
        >
          暂无商品
        </div>
      </div>
    </div>
    <div>
      <div style="text-align:center;padding-top:10px;">
        <el-pagination
          small
          background
          layout="pager,jumper"
          :page-size="15"
          :current-page="pages"
          :total="totals"
          @current-change="changes"
        >
        </el-pagination>
      </div>
      <div style="text-align:right;padding-right:20px;padding-bottom:20px;">
        <el-button size="small" @click="handleClose">取 消</el-button>
        <el-button size="small" type="primary" @click="addImg">确 定</el-button>
      </div>
    </div>
    <!-- </div> -->
  </el-dialog>
</template>

<script>
import { aGOODSLIST } from "@/service/public";
export default {
  name: "WareAlert",
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    id: {
      type: Number,
      default: -1
    },
    activityType: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      listData: [],
      pages: 1,
      totals: 0,
      types: 0
    };
  },
  watch: {
    visible(val) {
      if (val) {
        switch (this.activityType) {
          case 25:
            this.type = 2;
            break;
          case 26:
            this.type = 1;
            break;
          case 27:
            this.type = 4;
            break;
        }
        this.getList();
      }
    }
  },
  created() {},
  methods: {
    changes(page) {
      this.pages = page;
      this.listData();
    },
    async getList() {
      this.listData = [];
      let params = {
        activity_type: this.type,
        page: this.pages,
        pageshow: 15,
        activity_id: this.id
      };
      await aGOODSLIST(params).then(({ code, data, msg }) => {
        if (code === 200) {
          this.totals = data.count;
          data.list.forEach(ele => {
            this.listData.push({
              goods_name: ele.goods_name,
              join_low_price: ele.join_low_price,
              join_up_price: ele.join_up_price,
              sku_low_price: ele.sku_low_price,
              sku_up_price: ele.sku_up_price,
              goods_id: ele.goods_id,
              need_nums: ele.need_nums,
              check: false,
              src: ele.goods_cover
            });
          });
        } else {
          this.$message.error(msg);
        }
      });
    },

    handleClose() {
      this.$emit("out");
    },
    checkHandle(i) {
      this.listData[i].check = !this.listData[i].check;
    },
    addImg() {
      let list = this.listData.filter(item => {
        return item.check === true;
      });
      this.$emit("out", list);
    }
  }
};
</script>

<style scoped lang="scss">
.el-pagination {
  white-space: initial;
}
.currentImg {
  border: 2px solid #00ffff !important;
}
.form-select {
  width: 100px;
  transform-origin: left;
  margin-left: 20px;
}
.form-radio {
  font-size: 12px;
  transform-origin: left;
}
.form-inline-form {
  width: 200px;
  display: flex;
  flex-direction: row;
  align-items: top;
  justify-content: space-around;
  display: inline-block;
  margin-left: 160px;
  .form-inline-form-from {
    width: 80px;
  }
  .form-inline-form-to {
    width: 80px;
  }
}
.form-search {
  width: 200px;
  margin-left: 20px;
}
.form-input1 {
  position: relative;
  &::before {
    content: "价格";
    font-size: 12px;
    left: -49px;
    position: absolute;
  }
}
.form-input2 {
  position: relative;
  margin-left: 20px;
  &::before {
    content: "--";
    font-size: 12px;
    left: -25px;
    display: block;
    position: absolute;
    color: grey;
  }
}
.img_box {
  // position: absolute;
  // width: 96%;
  // height: 360px;
  // overflow-y: scroll;
  // display: flex;
  // flex-wrap: wrap;
  // justify-content: flex-start;
  // float: left;
  // z-index: 99;
  // margin: 5px auto;
  .img_item_border {
    float: left;
    z-index: 999999999;
    border: 1px solid rgba(grey, 0.4);
    height: 90px;
    width: 150px;
    margin: 5px 5px 0px;
    cursor: pointer;
    z-index: 99;
    border-radius: 5px;
    display: flex;
    align-items: center;
    img {
      width: 63px;
      height: 63px;
      // margin-top: 15%;
      border-radius: 5px;
      // border: 1px solid rgba(grey,0.4);
      margin-left: 5px;
    }
    div {
      margin-left: 3px;
      color: rgba(grey, 0.8);
      text-align: left;
    }
  }
}

.clearfix:before,
.clearfix:after {
  content: " ";
  display: table;
}
.clearfix:after {
  clear: both;
}
</style>
